package com.itheima.heimademo01.mapper;

import com.itheima.heimademo01.pojo.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

public interface UserMapper {
    // 查询用户是否存在
    @Select("select * from user where username = #{username}")
    User findByUserName(@Param("username") String username);

    // 注册
    @Insert("insert into user(username, password, create_time, update_time) values (#{username}, #{password}, now(), now())")
    void register(@Param("username") String username, @Param("password") String password);

    // 更新用户基本信息
    @Update("update user set nickname=#{user.nickname},email=#{user.email},update_time=#{user.updateTime} where id=#{user.id}")
    void update(@Param("user") User user);

    // 更新用户头像
    @Update("update user set user_pic=#{avatarUrl},update_time=now() where id=#{id}")
    void updateAvatar(@Param("avatarUrl") String avatarUrl, @Param("id") Integer id);

    // 更新用户密码
    @Update("update user set password=#{md5String},update_time=now() where id=#{id}")
    void updatePwd(@Param("md5String") String md5String, @Param("id") Integer id);


}
